﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataMaintenanceRecord" @search="()=>{getTableDataMaintenanceRecord();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="PlanId_FormItem" prop="PlanId" :label="$t('message.autotrans._Model_MaintenanceRecord_Plan')">
            <el-select v-model="searchDataMaintenanceRecord.PlanId" clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllPlans" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="EquipmentId_FormItem" prop="EquipmentId" :label="$t('message.autotrans._Model_MaintenanceRecord_Equipment')">
            <el-select v-model="searchDataMaintenanceRecord.EquipmentId" clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllEquipments" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaintainerId_FormItem" prop="MaintainerId" :label="$t('message.autotrans._Model_MaintenanceRecord_Maintainer')">
            <el-select v-model="searchDataMaintenanceRecord.MaintainerId" clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllMaintainers" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaintenanceTime_FormItem" prop="MaintenanceTime" :label="$t('message.autotrans._Model_MaintenanceRecord_MaintenanceTime')">
            <el-date-picker v-model="searchDataMaintenanceRecord.MaintenanceTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="FinishTime_FormItem" prop="FinishTime" :label="$t('message.autotrans._Model_MaintenanceRecord_FinishTime')">
            <el-date-picker v-model="searchDataMaintenanceRecord.FinishTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ActualHours_FormItem" prop="ActualHours" :label="$t('message.autotrans._Model_MaintenanceRecord_ActualHours')">
            <el-input v-model="searchDataMaintenanceRecord.ActualHours" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Result_FormItem" prop="Result" :label="$t('message.autotrans._Model_MaintenanceRecord_Result')">
            <el-select v-model="searchDataMaintenanceRecord.Result" clearable>
               <el-option key="Completed" value="Completed" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Completed')"></el-option>
               <el-option key="Cancelled" value="Cancelled" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Cancelled')"></el-option>
               <el-option key="Delayed" value="Delayed" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Delayed')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Note_FormItem" prop="Note" :label="$t('message.autotrans._Model_MaintenanceRecord_Note')">
            <el-input v-model="searchDataMaintenanceRecord.Note" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateTime_FormItem" prop="CreateTime" :label="$t('message.autotrans._Model_MaintenanceRecord_CreateTime')">
            <el-date-picker v-model="searchDataMaintenanceRecord.CreateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateTime_FormItem" prop="UpdateTime" :label="$t('message.autotrans._Model_MaintenanceRecord_UpdateTime')">
            <el-date-picker v-model="searchDataMaintenanceRecord.UpdateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateBy_FormItem" prop="CreateBy" :label="$t('message.autotrans._Model_MaintenanceRecord_CreateBy')">
            <el-input v-model="searchDataMaintenanceRecord.CreateBy" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateBy_FormItem" prop="UpdateBy" :label="$t('message.autotrans._Model_MaintenanceRecord_UpdateBy')">
            <el-input v-model="searchDataMaintenanceRecord.UpdateBy" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/MaintenanceRecordExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefMaintenanceRecord" v-bind="tableDataMaintenanceRecord">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/EquipmentManagement/MaintenanceRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementMaintenanceRecordIndex;true;Digitalmes.EquipmentManagement.Controllers;MaintenanceRecord">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { maintenancerecordApi } from '/@/api/equipmentmanagement/maintenancerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateMaintenanceRecord = reactive({
    
    AllPlans: [] as any[],
    AllEquipments: [] as any[],
    AllMaintainers: [] as any[],
});

const searchDataMaintenanceRecord = ref({
        PlanId: null,
        EquipmentId: null,
        MaintainerId: null,
        MaintenanceTime: undefined,
        FinishTime: undefined,
        ActualHours: null,
        Result: undefined,
        Note: '',
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
});

// 定义变量内容
const tableRefMaintenanceRecord = ref();
const tableDataMaintenanceRecord = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page关联计划'),key: 'MaintenanceRecord_Plan',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page关联设备'),key: 'MaintenanceRecord_Equipment',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page维护人员'),key: 'MaintenanceRecord_Maintainer',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page维护时间'),key: 'MaintenanceRecord_MaintenanceTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page完成时间'),key: 'MaintenanceRecord_FinishTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page实际工时'),key: 'MaintenanceRecord_ActualHours',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page维护结果'),key: 'MaintenanceRecord_Result',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminRemark'),key: 'MaintenanceRecord_Note',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateTime'),key: 'MaintenanceRecord_CreateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateTime'),key: 'MaintenanceRecord_UpdateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateBy'),key: 'MaintenanceRecord_CreateBy',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateBy'),key: 'MaintenanceRecord_UpdateBy',type: 'text',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataMaintenanceRecord = () => {
    tableRefMaintenanceRecord.value.doSearch(maintenancerecordApi().search, searchDataMaintenanceRecord.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataMaintenanceRecord)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataMaintenanceRecord)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataMaintenanceRecord)
};

// 删除
const onDelete = (row: any) => {
    maintenancerecordApi().delete([row.ID]).then(() => { getTableDataMaintenanceRecord()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefMaintenanceRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      maintenancerecordApi().delete(selectedids).then(() => { getTableDataMaintenanceRecord()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefMaintenanceRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataMaintenanceRecord)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataMaintenanceRecord)
};

const onExport = () => {
	const selected = tableRefMaintenanceRecord.value.getSelectedRows();
	if (selected.length > 0) {
		maintenancerecordApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		maintenancerecordApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetMaintenancePlans',[],false).then(x=>{stateMaintenanceRecord.AllPlans = x});
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetEquipments',[],false).then(x=>{stateMaintenanceRecord.AllEquipments = x});
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetFrameworkUsers',[],false).then(x=>{stateMaintenanceRecord.AllMaintainers = x});
        getTableDataMaintenanceRecord();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

